//
//  ScrollController.m
//  weiAai
//
//  Created by ibokan on 14-12-13.
//  Copyright (c) 2014年 ibokan. All rights reserved.
//

#import "ScrollController.h"
#import "zhuceController.h"
#import "dengluController.h"
@interface ScrollController ()<UIScrollViewDelegate>
@property (weak,nonatomic) UIPageControl*PageControl;
@property(strong,nonatomic) UIImageView *images;
@end

@implementation ScrollController


- (void)viewDidLoad
{
    [super viewDidLoad];
//    self.navigationController.navigationBarHidden = YES;
	//1.添加scrollview
    [self setUpScrollView];
    //2.添加pageController
    [self setUpPageController];
    [self setButton];
 
    
}
-(void)setUpScrollView
{  //1.添加
    UIScrollView *scroll =[[UIScrollView alloc]init];
    scroll.frame =self.view.bounds;
    scroll.delegate=self;
    [self.view addSubview:scroll];
    
    //2.添加图片
    
    CGFloat W =scroll.frame.size.width;
    CGFloat H =scroll.frame.size.height;
    for(int i=0;i<3;i++){
        self.images =[[UIImageView alloc]init];
        
        NSString *string =[NSString stringWithFormat:@"login_background_0%d",i+1];
        self.images.image =[UIImage imageNamed:string];
        
        //3.设置fram
        CGFloat X =i*W;
        CGFloat Y =0;
        
        _images.frame  =CGRectMake(X, Y, W, H);
        [ scroll addSubview:_images];
    }
    
    //4设置滚动尺寸
    scroll.contentSize =CGSizeMake(W*3, 0);
    //水平方向滚动条取消
    scroll.showsHorizontalScrollIndicator =NO;
    //自动一次就翻一页
    scroll.pagingEnabled = YES;
    //删除弹簧效果
    scroll.bounces =NO;
    
}
-(void)setUpPageController
{
    UIPageControl *page =[[UIPageControl alloc]init];
    //1.原点个数
    page.numberOfPages =3;
    //2.位置
    CGFloat pageX =self.view.frame.size.width*0.5;
    CGFloat pageY =self.view.frame.size.height-30;
    page.center =CGPointMake(pageX, pageY);
    page.bounds =CGRectMake(0, 0, 100, 30);
    //3.不让点
    page.userInteractionEnabled =NO;
    //4.
    [ self.view addSubview:page];
    self.PageControl =page;
    //设置原点颜色
    page.currentPageIndicatorTintColor =[UIColor redColor];
    page.pageIndicatorTintColor =[UIColor whiteColor];
}
/*
 只要scrollview滚动就会调用
 */
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //1.水平方向滚动的距离
    CGFloat setX =scrollView.contentOffset.x;
    //2.求出页码
    double page =setX/scrollView.frame.size.width;
    int pageInt =(int)(page+0.5);
    self.PageControl.currentPage =pageInt;
    
}
-(void)setButton
{
    UIButton*denglu1 =[[UIButton alloc]init];
    denglu1.frame =CGRectMake(20, 300, 100, 40);
    denglu1.backgroundColor =[UIColor redColor];
    [denglu1 setTitle:@"注册" forState:UIControlStateNormal];
    [self.view addSubview:denglu1];
    [denglu1 addTarget:self action:@selector(denglu11) forControlEvents:UIControlEventTouchDown];
    
    UIButton*denglu2 =[[UIButton alloc]init];
    denglu2.frame =CGRectMake(200, 300, 100, 40);
    denglu2.backgroundColor =[UIColor redColor];
    [denglu2 setTitle:@"登录" forState:UIControlStateNormal];
    [self.view addSubview:denglu2];
    [denglu2 addTarget:self action:@selector(denglu22) forControlEvents:UIControlEventTouchDown];
}
-(void)denglu11
{
   // [self.navigationController pushViewController:[[zhuceController alloc]init] animated:NO];
  UINavigationController *nav =[[UINavigationController alloc]init];

    self.view.window.rootViewController =nav;
    zhuceController *zhuce =[[zhuceController alloc]init];
    
    [nav pushViewController:zhuce animated:YES];

}
-(void)denglu22
{
    UINavigationController *nav1 =[[UINavigationController alloc]init];
    

    self.view.window.rootViewController =nav1;
 

    dengluController *denglu=[[dengluController alloc]init];
    
    [nav1 pushViewController:denglu animated:YES];


}
//- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
//{
//    if (viewController>0) {
//        viewController.hidesBottomBarWhenPushed = YES;
//    }
//   // [super pushViewController:viewController animated:animated];
//}

@end
